/**
 * CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

package com.cmcc.zysoft.infocollection.mobile.dao;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import com.starit.common.dao.hibernate.HibernateBaseDaoImpl;
import com.cmcc.zysoft.infocollection.model.Resource;

/**
 * @author 袁凤建
 * <br />邮箱: yuan.fengjian@ustcinfo.com
 * <br />描述: MResourceSDao.java
 * <br />版本: 1.0.0
 * <br />日期: 2013-8-12 下午4:37:23
 * <br />CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

@Repository
public class MResourceDao extends HibernateBaseDaoImpl<Resource, String> {

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	/**
	 * 个人中心-通过该接口,用户可查询自己的POI采集和更新信息(审核不通过的不计入统计范围).
	 * @param userId 用户ID
	 * @return map
	 */
	public List<Map<String, Object>> statCenter(String userId) {
		//说明: del_flag:0-未删除,1-已删除;data_flag:0-新增、1-更新、2-删除或为空白;pass_flag:1-通过,-1-不通过
		String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
		String sql = 
				" SELECT(SELECT COUNT(*) FROM tb_b_resource WHERE del_flag = '0' AND data_flag = '0' AND pass_flag <> '-1' AND add_date LIKE '%" + today + "%' AND add_man = ?) AS today_collection, " +
				" (SELECT  COUNT(*) FROM tb_b_resource WHERE del_flag = '0' AND data_flag = '1' AND pass_flag <> '-1' AND add_date LIKE '%" + today + "%' AND add_man = ?) AS today_update, " +
				" (SELECT  COUNT(*) FROM tb_b_resource WHERE del_flag = '0' AND data_flag = '0' AND pass_flag <> '-1'  AND add_man = ?) AS total_collection, " +
				" (SELECT COUNT(*) FROM tb_b_resource WHERE del_flag = '0' AND data_flag = '1' AND pass_flag <> '-1' AND add_man = ?) AS total_update";
		return this.jdbcTemplate.queryForList(sql, userId, userId, userId, userId);
	}
}